#{extends 'common/base.html' /}
<script>
	$(function() {
		var params = {};
		$("#yields_sub").click(function() {
			var sb = new StringBuffer();
			/*var realTotal = ${totalCutter};
			var inputTotal = 0;
			
			$("input[name='useplan']").each(function() {
					sb.append($(this).attr("materialId"))
 					sb.append("=")
					sb.append($(this).attr("materialId"))
					sb.append("=")
					sb.append($(this).attr("num"))
					sb.append(",")
			});
			if(inputTotal>realTotal){
			alert("安排数量不能大于实际用刀量!!");
			return false;
		}
			*/
			$("input[name='num']").each(function() {
				//inputTotal += parseInt($(this).val());		
				sb.append($(this).attr("operatorId"))
				sb.append("=")
				sb.append($(this).attr("materialId"))
				sb.append("=")
				sb.append($(this).val())
				sb.append(",")
			});
			var useplan = sb.toString();
			useplan = useplan.substring(0, useplan.length - 1);
			params["useplan"] = useplan;
			$("#yields_sub").html("正在向终端安排刀具，请稍候...");
			$("#yields_sub").attr("disable",true);
			$.post('arrangePlan', params, function(data) {
				$("#yields_sub").html("确认安排");
				$("#yields_sub").attr("disable",false);
				alert("完成安排");
				window.location.reload();
			})

		});
		
		
		$('#useClick').datepicker().on('changeDate.datepicker.amui',
				function(event) {
					$('#useDateStr').text($('#useClick').data('date'));
					$(this).datepicker('close');
				});
		$("#search_sub").click(function() {
			var url = "@{useplan.UsePlanAction.index}"+"?date="+$('#useClick').data('date');
			window.location.href=url;
		})
	})
</script>
<!-- content start -->
<div class="admin-content">
	<div class="am-cf am-padding">
		<div class="am-fl am-cf">
			<strong class="am-text-primary am-text-lg">安排刀具</strong> / <small>UsePlanIndex</small>
		</div>
	</div>
		<div class="am-g">
			<div class="am-u-sm-12 am-u-md-3" style="width: 50%;">
				<div class="am-form-group">
					实际需用刀数量:${totalCutter}
				</div>
			</div>
		</div>
		<div class="am-g">
			<div class="am-u-sm-12 am-u-md-3" style="width: 50%;">
				<div class="am-form-group">
					<button type="button" class="am-btn am-btn-default am-margin-right"
						id="useClick">领用日期</button>
					<span id="useDateStr"></span> <input hidden
						name="date" id="date"> &nbsp;&nbsp;&nbsp;
					<button class="am-btn am-btn-default" id="search_sub" type="button">搜索</button>
				</div>
			</div>
		</div>

	<div class="am-g">
		<div class="am-u-sm-12">
			<table class="am-table am-table-striped am-table-hover table-main">
				<thead>
					<tr>
						<th class="table-check"><input type="checkbox" /></th>
						<th class="table-id">序号</th>
						<th class="table-title">操作员姓名</th>
						<th class="table-title">刀具规格</th>
						<th class="table-title">数量</th>
						<th class="table-title">参与项目名称</th>
						<th class="table-title">安排日期</th>
						<th class="table-title">状态</th>
					</tr>
				</thead>
				<tbody>
					#{if uses!=null} #{set count:1/} #{list items:uses.data,as:'bean'}
					<tr>
						<td><input type="checkbox" />
						</td>
						<td>${count}</td>
						<td>${bean?.real_name}</td>
						<td>${bean?.cutter_specs}</td>
						<td>
						#{if bean?.is_confirm==1}
							<input name="num" type="text" disabled="disabled" operatorId = "${bean?.operator_id}" materialId="${bean?.material_id}" value="${bean?.num}"></td>
						#{/if}
						#{else}
							<input name="num" type="text"  operatorId = "${bean?.operator_id}" materialId="${bean?.material_id}" value="${bean?.num}"></td>
						#{/else}
						
						<td>${bean?.project_name}</td>
						<td>${bean?.date}</td>
						<td>
						#{if bean?.is_confirm==1}
							已安排
						#{/if}
						#{else}
							未安排
						#{/else}
						</td>
					</tr>
					#{set count:count+1/} #{/list} #{/if}
				</tbody>
			</table>
		</div>
	</div>
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<button class="am-btn am-btn-default" id="yields_sub" type="button">确认安排</button>
</div>
<!-- content end -->